﻿using Remote;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XinYi.CrookedShowMode;
using XinYi.CrookedTopShow.DAL;

namespace XinYi.CrookedTopShow.BLL
{
    public class SMSInfoSerivice
    {
        /// <summary>
        /// 获取验证码同时将验证码保存至数据库
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public bool GetCode(string phone)
        {
            TenXunYunSMS tenXunYunSMS;
            //try
            //{
            tenXunYunSMS = new TenXunYunSMS();
            tenXunYunSMS.appId = Convert.ToInt32(ConfigurationManager.AppSettings["appId"]);
            tenXunYunSMS.appKey = ConfigurationManager.AppSettings["appKey"];
            tenXunYunSMS.SetSMS(phone);
            //}
            //catch (Exception)
            //{
            //    return false;
            //}
            SMSInfoRepository sMSInfoRepository = new SMSInfoRepository();
            SMSInfo sMSInfo = new SMSInfo();
            sMSInfo.Code = tenXunYunSMS.Code;
            sMSInfo.TelPhone = Convert.ToInt64(phone);
            return sMSInfoRepository.InsertSMSInfo(sMSInfo) > 0;
        }
        /// <summary>
        /// 查询电话和验证码是否正确
        /// </summary>
        /// <param name="sMSInfo"></param>
        /// <returns></returns>
        public bool SelCodePhone(SMSInfo sMSInfo)
        {
            SMSInfoRepository sMSInfoRepository = new SMSInfoRepository();
            return sMSInfoRepository.SelCodePhone(sMSInfo) > 0;
        }
    }
}
